## dockerfile
FROM centos:7.6.1810

ADD soft/libxml2-2.7.2.tar.gz /root/
ADD soft/jpegsrc.v8b.tar.gz /root/
ADD soft/zlib-1.2.11.tar.gz /root/
ADD soft/libpng-1.4.22.tar.gz /root/
ADD soft/freetype-2.4.1.tar.gz /root/
ADD soft/php-7.1.27.tar.gz /root/
ADD soft/libgd-2.1.1.tar.gz /root/
ADD soft/redis-4.3.0.tgz /root/
ADD soft/m4-1.4.9.tar.gz /root/
ADD soft/autoconf-2.62.tar.gz /root/
ADD soft/nginx.repo /etc/yum.repos.d/nginx.repo


RUN mkdir -p /root/.pip/ && mkdir /etc/supervisor
ADD soft/pip.conf /root/.pip/
ADD soft/supervisord.conf /etc/supervisor/supervisord.conf

# 依赖库
RUN yum update -y && yum install -y yum-fastestmirror perl-Module-Install.noarch libaio numactl python-devel tkinter perl pcre-devel net-tools gcc gcc-c++ zlib zlib-devel make openssl openssl-devel curl curl-devel ibmcrypt-devel libXpm-devel freetype-devel glib2-devel cairo-devel nginx

# make && make install 
RUN cd /root/libxml2-2.7.2 && ./configure --prefix=/usr/local/libxml2 --without-zlib && make && make install && \
rm -rf /root/libxml2-2.7.2 && cd / && \
cd /root/jpeg-8b && ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static && make && make install && \
rm -rf /root/jpeg-8b && cd / && \
cd /root/zlib-1.2.11 && ./configure && make && make install && \
rm -rf /root/zlib-1.2.11 && cd / && \
cd /root/libpng-1.4.22 && ./configure && make && make install && \
rm -rf /root/libpng-1.4.22 && cd / && \
cd /root/freetype-2.4.1 && ./configure --prefix=/usr/local/freetype && make && make install && \
rm -rf /root/freetype-2.4.1 && cd / && \
cd /root/libgd-2.1.1 && ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg/ --with-freetype=/usr/local/freetype && make && make install && \
rm -rf /root/libgd-2.1.1 && cd / && \
cd /root/m4-1.4.9 && ./configure && make && make install && \
rm -rf /root/m4-1.4.9 && cd / && \
cd /root/autoconf-2.62 && ./configure && make && make install && \
rm -rf /root/autoconf-2.62 && cd / && \
cd /root/php-7.1.27 && ./configure --prefix=/usr/local/php --enable-zip --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir=/usr/local/freetype --with-gd --with-curl  --with-zlib --with-libxml-dir=/usr/local/libxml2 --with-jpeg-dir=/usr/local/jpeg --with-png-dir --enable-mbstring=all --enable-mbregex --enable-shared --with-openssl --enable-fpm  --with-config-file-path=/usr/local/php/etc --with-xpm-dir=/usr/lib --enable-phpdbg && \
make && make install && \
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && \
cd /root/php-7.1.27 && cp ./sapi/fpm/php-fpm.service /etc/systemd/system/php-fpm.service && \
echo "export PATH=$PATH:/usr/local/php/bin" >> /etc/bashrc && source /etc/bashrc

# redis 拓展
RUN cd /root/redis-4.3.0 && /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install

# python pip supervisor
RUN curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py && python get-pip.py && pip install supervisor==4.2.0 

ADD soft/www.conf /usr/local/php/etc/php-fpm.d/
ADD soft/php.ini /usr/local/php/etc/php.ini

RUN  groupadd -g 1000 www && useradd -u1001 -g www  -s /bin/nologin www

RUN chmod 644 /etc/systemd/system/php-fpm.service && systemctl enable php-fpm && systemctl enable nginx && yum clean all && rm -rf /var/cache/yum && rm -rf /root/*

EXPOSE 9000 80

ENTRYPOINT ["/usr/bin/supervisord","-c","/etc/supervisor/supervisord.conf"]

# docker build -t adongphp:1.0 ./

# docker run -itd --restart=always --privileged=true --name phpweb -p 80:80 -v /Users/adong/code/docker/php/webroot:/home/webroot:rw -v /Users/adong/code/docker/php/nginx.conf:/etc/nginx/conf.d/nginx.conf:rw adongphp:1.0



# docker run -itd --restart=always --privileged=true --name phpweb -p 80:80 -v /Users/adong/www/yii:/home/webroot:rw -v /Users/adong/code/docker/php/nginx.conf:/etc/nginx/conf.d/nginx.conf:rw adongphp:1.0